package com.eling.elcms.travel.util;

import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

public final class DateHandlerUtil {

	// 计算两个日期相差天数
	public static int daysOfTwoDate(Date start, Date end) {
		Calendar aCalendar = Calendar.getInstance();
		aCalendar.setTime(start);
		int day1 = aCalendar.get(Calendar.DAY_OF_YEAR);
		aCalendar.setTime(end);
		int day2 = aCalendar.get(Calendar.DAY_OF_YEAR);
		return day2 - day1;
	}

	// 计算两个日期之间的每一天
	public static Set<Date> timeOfDaysByTwoDate(Date start, Date end) {
		Set<Date> dateSet = new HashSet<>();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(start);

		while (calendar.getTime().before(end)) {
			dateSet.add(calendar.getTime());
			calendar.add(Calendar.DAY_OF_MONTH, 1);
		}
		return dateSet;
	}

}
